package com.wangshuqi.filter;

import javax.servlet.*;
import java.io.IOException;

public class CharsetEncodingFilter implements Filter {

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("CharsetEncodingFilter init..");
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        request.setCharacterEncoding("GBK");
        response.setCharacterEncoding("GBK");
        chain.doFilter(request, response);
    }

    @Override
    public void destroy() {
        System.out.println("CharsetEncodingFilter destroy..");
    }
}
